﻿using Lazy.Captcha.Core;
using Microsoft.AspNetCore.Mvc;
using NewCodeAPI.IServices;

namespace NewCodeAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : Controller
    {
        private readonly IUserService _userService;
        private readonly ICaptcha _captcha;

        public UserController(IUserService userService, ICaptcha captcha)
        {
            _userService = userService;
            _captcha = captcha;
        }

        [HttpPost]
        public MsgInfo Register(string username, string password)
        {
            return _userService.Register(username, password);
        }

        [HttpGet]
        public IActionResult Captcha()
        {
            string id = "wdh007";
            var info = _captcha.Generate(id);
            var stream = new MemoryStream(info.Bytes);
            return File(stream, "image/gif");
        }

        [HttpPost]
        public MsgInfo Login(string username, string password, string code)
        {
            return _userService.Login(username, password, code);
        }

    }
}
